#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>

#include <sys/ioctl.h>
#include <linux/videodev2.h>

int main(void)
{
    int fd = open("/dev/video1",O_RDWR);
    if(fd < 0){
        printf("打开设备失败\r\n");
        return -1;
    }
    struct v4l2_fmtdesc vfmt;
    vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    int i = 0;
    while(1){
        vfmt.index = i;
        i++;
        int ret = ioctl(fd,VIDIOC_ENUM_FMT,&vfmt);
        if(ret < 0){
            perror("获取失败");
            break;
        }
        printf("index = %d\n",vfmt.index);
        printf("flags = %d\n",vfmt.flags);
        printf("description = %s\n",vfmt.description);
        unsigned char *p = (unsigned char *)&vfmt.pixelformat;
        printf("plexelformat = %c%cc%c\n",p[0],p[1],p[2]);
        printf("reserved = %d\n",vfmt.reserved[0]);
    }
}